package com.example.androidframework.ui.course

import androidx.fragment.app.Fragment
import com.example.androidframework.R
import com.example.androidframework.databinding.FragmentCourseBinding
import com.example.androidframework.ui.course.flow.FlowActivity
import com.martin.lib_base.base.BaseFragment
import com.martin.lib_base.interfaces.IOnItemClickListener
import com.martin.lib_base.ktx.addOnItemClickListener
import com.martin.lib_base.ktx.loge
import com.martin.lib_base.ktx.refresh

class CourseFragment : BaseFragment<FragmentCourseBinding, CourseViewModel>() {
    override fun getViewModelClass(): Class<CourseViewModel> {
        return CourseViewModel::class.java
    }

    override fun layoutId(): Int {
        return R.layout.fragment_course
    }

    override fun initOnViewCreated() {
        binding.viewModel = viewModel
        // 刷新数据
        binding.rv.refresh(viewModel.itemList)
        // 点击监听
        binding.rv.addOnItemClickListener(object : IOnItemClickListener {
            override fun onItemClick(position: Int, type: Int) {
                loge("onItemClick position = $position")
               viewModel.onItemClick(requireContext(), position)
            }

        })
    }

    companion object {
        fun getInstance() : Fragment {
            return CourseFragment()
        }
    }
}